{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MUSCLE Web services from BioServices"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MUSCLE service allows you to perform sequence alignment between sequences."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, we first use UniProt to fetch two sequences"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from bioservices import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "m = MUSCLE(verbose=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "u = UniProt()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Will be moved to BioKit github.com/biokit\n",
      "Will be moved to BioKit github.com/biokit\n"
     ]
    }
   ],
   "source": [
    "f1 = u.get_fasta(\"P18413\")\n",
    "f2 = u.get_fasta(\"P18412\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'>sp|P18413|ERD2_KLULA ER lumen protein-retaining receptor OS=Kluyveromyces lactis (strain ATCC 8585 / CBS 2359 / DSM 70799 / NBRC 1267 / NRRL Y-1140 / WM37) GN=ERD2 PE=3 SV=1\\nMLNVFRIAGDFSHLASIIILIQSITTSNSVDGISLKTQLLYTLVFITRYLNLFTKWTSLY\\nNFLMKIVFISSSVYVIVLMRQQKFKNPVAYQDMITRDQFKIKFLIVPCILLGLIFNYRFS\\nFIQICWSFSLWLESVAILPQLFMLTKTGKAKQLTSHYIFALGLYRALYIPNWIWRYYTEE\\nRFDKLSVFTGVIQTLVYSDFFYIYYQKVIKLGGDLELPQ\\n'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "jobid = m.run(frmt=\"fasta\", sequence=f1+f2, email=\"test@ebi.ac.uk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "res = m.getResult(jobid, \"out\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started Thu Feb 25 13:05:18 2016\n",
      "/nfs/public/ro/es/appbin/linux-x86_64/muscle-3.8.31/muscle -in muscle-R20160225-130449-0208-15245944-pg.sequence -verbose -log muscle-R20160225-130449-0208-15245944-pg.output -quiet -fasta -out muscle-R20160225-130449-0208-15245944-pg.fasta \n",
      "Alphabet Amino\n",
      "\n",
      "MUSCLE v3.8.31 by Robert C. Edgar\n",
      "http://www.drive5.com/muscle\n",
      "\n",
      "Profile-profile score    LE\n",
      "Max iterations           8\n",
      "Max trees                1\n",
      "Max time                 (No limit)\n",
      "Max MB                   1227\n",
      "Gap open                 -2.9\n",
      "Gap extend (dimer)       0\n",
      "Gap ambig factor         0\n",
      "Gap ambig penalty        -0\n",
      "Center (LE)              -0.52\n",
      "Term gaps                Half\n",
      "Smooth window length     7\n",
      "Refine window length     200\n",
      "Min anchor spacing       32\n",
      "Min diag length (lambda) 24\n",
      "Diag margin (mu)         5\n",
      "Min diag break           1\n",
      "Hydrophobic window       5\n",
      "Hydrophobic gap factor   1.2\n",
      "Smooth score ceiling     3\n",
      "Min best col score       2\n",
      "Min anchor score         1\n",
      "SUEFF                    0.1\n",
      "Brenner root MSA         False\n",
      "Normalize counts         True\n",
      "Diagonals (1)            False\n",
      "Diagonals (2)            False\n",
      "Anchors                  True\n",
      "MSF output format        False\n",
      "Phylip interleaved       False\n",
      "Phylip sequential        False\n",
      "ClustalW output format   False\n",
      "Catch exceptions         True\n",
      "Quiet                    True\n",
      "Refine                   False\n",
      "ProdfDB                  False\n",
      "Low complexity profiles  True\n",
      "Objective score          SPM\n",
      "Distance method (1)      Kmer6_6\n",
      "Clustering method (1)    UPGMB\n",
      "Root method (1)          Pseudo\n",
      "Sequence weighting (1)   ClustalW\n",
      "Distance method (2)      PctIdKimura\n",
      "Clustering method (2)    UPGMB\n",
      "Root method (2)          Pseudo\n",
      "Sequence weighting (2)   ClustalW\n",
      "\n",
      "Elapsed time 00:00:00  Peak memory use    11 MB(1%)  Iteration   1 K-mer dist pass 1\n",
      "Elapsed time 00:00:00  Peak memory use    11 MB(1%)  Iteration   1 K-mer dist pass 2\n",
      "Align: (sp|P18413|ERD2_KLULA ER lumen protein-retaining receptor OS=Kluyveromyces lactis (strain ATCC 8585 / CBS 2359 / DSM 70799 / NBRC 1267 / NRRL Y-1140 / WM37) GN=ERD2 PE=3 SV=1) (sp|P18412|TEC1_YEAST Ty transcription activator TEC1 OS=Saccharomyces cerevisiae (strain ATCC 204508 / S288c) GN=TEC1 PE=1 SV=1)\n",
      "Elapsed time 00:00:00  Peak memory use    13 MB(1%)  Iteration   1 Align node\n",
      "Elapsed time 00:00:00  Peak memory use    13 MB(1%)  Iteration   1 Root alignment\n",
      "Finished Thu Feb 25 13:05:18 2016\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
